# -*- coding: utf-8 -*-
import sys,os
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon,QAction,QMenu,QMessageBox
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import QCoreApplication
from GUI import magician_main
from it_toolkits import it_toolkits as it

if __name__ == '__main__':

    app = QApplication(sys.argv)
    QApplication.setQuitOnLastWindowClosed(False)
    w = magician_main.MainWindow()
    w.move(1570, 200)
    # window.resize(50, 50)
    w.setAutoFillBackground(True)
    tp = QSystemTrayIcon(w)
    tp.setIcon(QIcon(r'icons/magisian.ico'))

    def quitApp():
        re = QMessageBox.question(w, "提示", "确定要退出吗？", QMessageBox.Yes |
            QMessageBox.No, QMessageBox.No)
        if re == QMessageBox.Yes:
            w.hide()
            QCoreApplication.instance().quit()
            tp.setVisible(False)
    # 增加it菜单
    tpMenu = QMenu()
    Qact = dict()
    for k,v in it.all_func.items():
        if k:
            Qact[k] = QAction(k,triggered = eval('it.%s'%v))
            tpMenu.addAction(Qact[k])
            # pass

    a20 = QAction('&退出（Exit）', triggered=quitApp)  # 直接退出可以用qApp.quit

    tpMenu.addAction(a20)
    a20.setEnabled(1)
    tp.setContextMenu(tpMenu)
    tp.show()

    # tp.showMessage('十月文化','内部专用工具，双击或右键使用',icon=0)

    def act(reason):
        if reason == 2:
            w.show()
            w.raise_()
    tp.activated.connect(act)

    app.exec_()
